<?php
/**
 * 联系表单组件
 * 所有文本信息完全通过$data配置，无任何硬编码
 */
$configKey = isset($configKey) ? $configKey : 'feedback-form';

// 意见反馈表单配置（针对反馈场景优化）
$defaultConfig = [
    'section_id' => $configKey,
    'section_title' => '提交您的意见反馈',
    'section_subtitle' => '您的每一条建议或体验分享，都是我们优化的动力',
    'action' => '/submit-feedback.php', // 反馈提交处理接口
    'method' => 'post',
    'success_message' => '反馈提交成功！感谢您的宝贵意见，我们会认真参考',
    'error_message' => '反馈提交失败，请检查信息后重试',
    'network_error_message' => '网络连接错误，请检查网络后重试',
    'texts' => [
        'default_field_error' => '此字段无效',
        'required_field_error' => '此字段为必填项',
        'max_length_error' => '最多可输入{max}个字符',
        'file_size_error' => '文件大小不能超过{max_size}MB',
        'view_feedback_progress' => '查看历史反馈处理进度',
        'privacy_link_text' => '隐私政策',
        'view_details' => '查看详情',
        'upload_file_text' => '点击上传文件',
        'or_drop_file' => '或拖放文件至此',
        'file_format_hint' => '支持JPG/PNG/GIF，最大5MB'
    ],
    'fields' => [
        // 基础信息：保留核心必填项，简化非必要字段
        [
            'name' => 'nickname',
            'label' => '您的昵称',
            'type' => 'text',
            'required' => true,
            'placeholder' => '请输入您的昵称（仅用于标识反馈者）',
            'validation' => [
                'min_length' => 1,
                'max_length' => 20,
                'error_message' => '昵称需1-20个字符'
            ]
        ],
        [
            'name' => 'contact',
            'label' => '联系方式（选填）',
            'type' => 'text',
            'required' => false,
            'placeholder' => '邮箱/电话（如需回复请填写）',
            'validation' => [
                'error_message' => '请填写有效的联系方式'
            ]
        ],
        // 反馈核心字段：新增场景分类和满意度评分
        [
            'name' => 'feedback_type',
            'label' => '反馈类型',
            'type' => 'select',
            'required' => true,
            'options' => [
                '' => '请选择反馈类型',
                'suggestion' => '功能建议',
                'bug' => '问题/BUG反馈',
                'experience' => '体验优化',
                'complaint' => '投诉建议',
                'other' => '其他反馈'
            ],
            'validation' => [
                'error_message' => '请选择反馈类型'
            ]
        ],
        [
            'name' => 'satisfaction',
            'label' => '整体满意度',
            'type' => 'radio',
            'required' => true,
            'options' => [
                '5' => '非常满意',
                '4' => '满意',
                '3' => '一般',
                '2' => '不满意',
                '1' => '非常不满意'
            ],
            'validation' => [
                'error_message' => '请选择满意度'
            ]
        ],
        // 反馈内容：保留大文本框，优化提示文案
        [
            'name' => 'feedback_content',
            'label' => '反馈详情',
            'type' => 'textarea',
            'required' => true,
            'placeholder' => '请详细描述您的建议、问题或体验（例：希望新增XX功能/XX页面加载缓慢）',
            'rows' => 6,
            'validation' => [
                'min_length' => 10,
                'max_length' => 3000,
                'error_message' => '反馈内容需至少10个字符，最多3000字符'
            ]
        ],
        // 附加功能：支持上传截图（反馈问题时更直观）
        [
            'name' => 'screenshot',
            'label' => '上传截图（选填）',
            'type' => 'file',
            'required' => false,
            'accept' => 'image/jpeg,image/png,image/gif',
            'placeholder' => '支持JPG/PNG/GIF，最大5MB',
            'validation' => [
                'max_size' => 5242880, // 5MB
                'error_message' => '仅支持JPG/PNG/GIF格式，文件不超过5MB'
            ]
        ],
        // 隐私协议：保留合规性字段
        [
            'name' => 'privacy_accept',
            'label' => '我已阅读并同意反馈隐私政策',
            'type' => 'checkbox',
            'required' => true,
            'validation' => [
                'error_message' => '需同意隐私政策才能提交反馈'
            ]
        ]
    ],
    'submit_text' => '提交反馈',
    'submit_loading_text' => '提交中...',
    'privacy_note' => '提交即表示您同意我们不会将您的反馈信息用于非反馈处理用途',
    'privacy_link' => '/feedback-privacy.php', // 反馈专用隐私政策
    'bg_color' => 'white',
    'features' => [
        [
            'icon' => 'fa fa-lightbulb-o',
            'title' => '您的建议会被重视',
            'subtitle' => '每一条反馈都会进入我们的优化清单，定期公示处理进度'
        ],
        [
            'icon' => 'fa fa-lock',
            'title' => '隐私安全有保障',
            'subtitle' => '您的个人信息仅用于反馈沟通，不会泄露给第三方'
        ],
        [
            'icon' => 'fa fa-reply',
            'title' => '如需可获回复',
            'subtitle' => '填写联系方式后，我们会针对您的反馈给出专属回复'
        ]
    ]
];
$formConfig = array_merge($defaultConfig, $pageConfig['components'][$configKey] ?? []);
// 处理背景样式（保持原逻辑）
$bgClass = "bg-{$formConfig['bg_color']}";
?>

<!-- 意见反馈表单布局（保留原美观设计） -->
<div class="min-h-screen bg-gradient-to-br from-gray-50 to-gray-100 py-12 px-4 sm:px-6">
    <div class="max-w-7xl mx-auto">
        <div class="grid grid-cols-1 lg:grid-cols-2 gap-12">
            <!-- 左侧内容区域：替换为反馈场景文案 -->
            <div class="flex flex-col justify-center">
                <div class="mb-8">
                    <h2 class="text-4xl font-bold text-gray-900 mb-4">
                        <?php echo htmlspecialchars($formConfig['section_title'] ?? '提交您的意见反馈'); ?>
                    </h2>
                    <p class="text-lg text-gray-600">
                        <?php echo htmlspecialchars($formConfig['section_subtitle'] ?? '您的反馈，是我们进步的方向'); ?>
                    </p>
                </div>
                
                <!-- 反馈价值说明（新增模块） -->
                <div class="space-y-4 mb-8">
                    <?php foreach(($formConfig['features'] ?? []) as $item): ?>
                    <div class="flex items-start">
                        <div class="flex-shrink-0 w-10 h-10 rounded-full bg-blue-100 flex items-center justify-center text-blue-600">
                            <i class="fa <?php echo htmlspecialchars($item['icon'] ?? ''); ?>"></i>
                        </div>
                        <div class="ml-4">
                            <h4 class="font-semibold text-gray-900"><?php echo htmlspecialchars($item['title'] ?? ''); ?></h4>
                            <p class="text-gray-600 text-sm"><?php echo htmlspecialchars($item['subtitle'] ?? ''); ?></p>
                        </div>
                    </div>
                    <?php endforeach; ?>
                </div>
                
                <!-- 反馈进度入口（新增模块） -->
                <a href="/feedback-progress.php" class="inline-flex items-center text-blue-600 hover:text-blue-800 font-medium">
                    <?php echo htmlspecialchars($formConfig['texts']['view_feedback_progress']); ?>
                    <i class="fa fa-angle-right ml-1"></i>
                </a>
            </div>
            
            <!-- 右侧表单区域：核心逻辑保留，适配新字段 -->
            <div class="bg-white rounded-2xl shadow-xl overflow-hidden">
                <div class="bg-gradient-to-r from-blue-600 to-indigo-700 p-8 text-white">
                    <h3 class="text-2xl font-bold mb-2">
                        <?php echo htmlspecialchars($formConfig['section_title'] ?? '提交您的意见反馈'); ?>
                    </h3>
                    <p class="opacity-90">
                        <?php echo htmlspecialchars($formConfig['section_subtitle'] ?? '我们会认真对待每一条反馈'); ?>
                    </p>
                </div>
                
                <div class="p-8">
                    <!-- 表单状态反馈（保留原逻辑） -->
                    <div id="form-success" class="hidden mb-6 p-4 bg-green-50 border border-green-200 rounded-lg text-green-800">
                        <div class="flex">
                            <i class="fa fa-check-circle text-green-500 mt-0.5 mr-3"></i>
                            <span><?php echo htmlspecialchars($formConfig['success_message']); ?></span>
                        </div>
                    </div>
                    
                    <div id="form-error" class="hidden mb-6 p-4 bg-red-50 border border-red-200 rounded-lg text-red-800">
                        <div class="flex">
                            <i class="fa fa-exclamation-circle text-red-500 mt-0.5 mr-3"></i>
                            <span id="form-error-text"><?php echo htmlspecialchars($formConfig['error_message']); ?></span>
                        </div>
                    </div>
                    
                    <!-- 反馈表单（适配新字段） -->
                    <form 
                        action="<?php echo htmlspecialchars($formConfig['action']); ?>" 
                        method="<?php echo htmlspecialchars($formConfig['method']); ?>"
                        class="space-y-6"
                        id="feedbackForm"
                        enctype="multipart/form-data"
                        novalidate
                    >
                        <?php foreach ($formConfig['fields'] as $index => $field): ?>
                            <div class="form-group">
                                <!-- 非复选框/单选框：显示常规标签 -->
                                <?php if (!in_array($field['type'], ['checkbox', 'radio'])): ?>
                                    <label for="<?php echo htmlspecialchars($field['name']); ?>" class="block text-gray-700 font-medium mb-2">
                                        <?php echo htmlspecialchars($field['label']); ?>
                                        <?php if ($field['required']): ?>
                                            <span class="text-red-500">*</span>
                                        <?php endif; ?>
                                    </label>
                                <?php endif; ?>
                                
                                <!-- 错误提示（保留原逻辑） -->
                                <div class="error-message text-red-500 text-sm mb-2 hidden"></div>
                                
                                <!-- 文本域：反馈详情 -->
                                <?php if ($field['type'] === 'textarea'): ?>
                                    <textarea 
                                        id="<?php echo htmlspecialchars($field['name']); ?>"
                                        name="<?php echo htmlspecialchars($field['name']); ?>"
                                        rows="<?php echo $field['rows'] ?? 4; ?>"
                                        placeholder="<?php echo htmlspecialchars($field['placeholder'] ?? ''); ?>"
                                        <?php echo $field['required'] ? 'required' : ''; ?>
                                        data-validation="<?php echo htmlspecialchars(json_encode($field['validation'] ?? [])); ?>"
                                        class="w-full px-4 py-3 rounded-lg border border-gray-300 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent transition-all duration-300"
                                    ></textarea>
                                
                                <!-- 下拉选择：反馈类型 -->
                                <?php elseif ($field['type'] === 'select'): ?>
                                    <div class="relative">
                                        <select 
                                            id="<?php echo htmlspecialchars($field['name']); ?>"
                                            name="<?php echo htmlspecialchars($field['name']); ?>"
                                            <?php echo $field['required'] ? 'required' : ''; ?>
                                            data-validation="<?php echo htmlspecialchars(json_encode($field['validation'] ?? [])); ?>"
                                            class="w-full px-4 py-3 rounded-lg border border-gray-300 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent appearance-none transition-all duration-300"
                                        >
                                            <?php foreach ($field['options'] as $value => $label): ?>
                                                <option value="<?php echo htmlspecialchars($value); ?>"><?php echo htmlspecialchars($label); ?></option>
                                            <?php endforeach; ?>
                                        </select>
                                        <div class="pointer-events-none absolute inset-y-0 right-0 flex items-center px-3 text-gray-500">
                                            <i class="fa fa-chevron-down"></i>
                                        </div>
                                    </div>
                                
                                <!-- 单选框：满意度评分（新增字段逻辑） -->
                                <?php elseif ($field['type'] === 'radio'): ?>
                                    <label class="block text-gray-700 font-medium mb-2">
                                        <?php echo htmlspecialchars($field['label']); ?>
                                        <?php if ($field['required']): ?>
                                            <span class="text-red-500">*</span>
                                        <?php endif; ?>
                                    </label>
                                    <div class="flex flex-wrap gap-4">
                                        <?php foreach ($field['options'] as $value => $label): ?>
                                            <div class="flex items-center">
                                                <input 
                                                    id="<?php echo htmlspecialchars($field['name'] . '-' . $value); ?>"
                                                    name="<?php echo htmlspecialchars($field['name']); ?>"
                                                    type="radio"
                                                    value="<?php echo htmlspecialchars($value); ?>"
                                                    <?php echo $field['required'] ? 'required' : ''; ?>
                                                    data-validation="<?php echo htmlspecialchars(json_encode($field['validation'] ?? [])); ?>"
                                                    class="w-4 h-4 text-blue-600 focus:ring-blue-500 border-gray-300 rounded"
                                                >
                                                <label for="<?php echo htmlspecialchars($field['name'] . '-' . $value); ?>" class="ml-2 text-gray-700">
                                                    <?php echo htmlspecialchars($label); ?>
                                                </label>
                                            </div>
                                        <?php endforeach; ?>
                                    </div>
                                
                                <!-- 文件上传：截图（新增字段逻辑） -->
                                <?php elseif ($field['type'] === 'file'): ?>
                                    <div class="mt-1 flex justify-center px-6 pt-5 pb-6 border-2 border-gray-300 border-dashed rounded-lg">
                                        <div class="space-y-1 text-center">
                                            <i class="fa fa-cloud-upload text-3xl text-gray-400"></i>
                                            <div class="flex text-sm text-gray-600">
                                                <label for="<?php echo htmlspecialchars($field['name']); ?>" class="relative cursor-pointer bg-white rounded-md font-medium text-blue-600 hover:text-blue-500 focus-within:outline-none">
                                                    <span><?php echo htmlspecialchars($formConfig['texts']['upload_file_text']); ?></span>
                                                    <input 
                                                        id="<?php echo htmlspecialchars($field['name']); ?>"
                                                        name="<?php echo htmlspecialchars($field['name']); ?>"
                                                        type="file"
                                                        <?php echo $field['required'] ? 'required' : ''; ?>
                                                        <?php echo !empty($field['accept']) ? 'accept="' . htmlspecialchars($field['accept']) . '"' : ''; ?>
                                                        data-validation="<?php echo htmlspecialchars(json_encode($field['validation'] ?? [])); ?>"
                                                        class="sr-only"
                                                    >
                                                </label>
                                                <p class="pl-1"><?php echo htmlspecialchars($formConfig['texts']['or_drop_file']); ?></p>
                                            </div>
                                            <p class="text-xs text-gray-500">
                                                <?php echo htmlspecialchars($field['placeholder'] ?? $formConfig['texts']['file_format_hint']); ?>
                                            </p>
                                        </div>
                                    </div>
                                
                                <!-- 复选框：隐私协议（保留原逻辑） -->
                                <?php elseif ($field['type'] === 'checkbox'): ?>
                                    <div class="flex items-start p-4 rounded-lg border border-gray-200 hover:border-blue-300 transition-colors duration-300">
                                        <div class="flex items-center h-5">
                                            <input 
                                                id="<?php echo htmlspecialchars($field['name']); ?>"
                                                name="<?php echo htmlspecialchars($field['name']); ?>"
                                                type="checkbox"
                                                <?php echo $field['required'] ? 'required' : ''; ?>
                                                data-validation="<?php echo htmlspecialchars(json_encode($field['validation'] ?? [])); ?>"
                                                class="w-5 h-5 text-blue-600 focus:ring-blue-500 border-gray-300 rounded"
                                            >
                                        </div>
                                        <div class="ml-3 text-sm">
                                            <label for="<?php echo htmlspecialchars($field['name']); ?>" class="text-gray-700">
                                                <?php echo htmlspecialchars($field['label']); ?>
                                                <?php if ($field['required']): ?>
                                                    <span class="text-red-500">*</span>
                                                <?php endif; ?>
                                            </label>
                                            <?php if (!empty($formConfig['privacy_link'])): ?>
                                                <a href="<?php echo htmlspecialchars($formConfig['privacy_link']); ?>" class="text-blue-600 hover:underline ml-1" target="_blank">
                                                    <?php echo htmlspecialchars($formConfig['texts']['privacy_link_text']); ?>
                                                </a>
                                            <?php endif; ?>
                                        </div>
                                    </div>
                                
                                <!-- 其他输入类型：文本、邮箱等 -->
                                <?php else: ?>
                                    <input 
                                        type="<?php echo htmlspecialchars($field['type']); ?>"
                                        id="<?php echo htmlspecialchars($field['name']); ?>"
                                        name="<?php echo htmlspecialchars($field['name']); ?>"
                                        placeholder="<?php echo htmlspecialchars($field['placeholder'] ?? ''); ?>"
                                        <?php echo $field['required'] ? 'required' : ''; ?>
                                        data-validation="<?php echo htmlspecialchars(json_encode($field['validation'] ?? [])); ?>"
                                        class="w-full px-4 py-3 rounded-lg border border-gray-300 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent transition-all duration-300"
                                    >
                                <?php endif; ?>
                            </div>
                        <?php endforeach; ?>
                        
                        <?php if (!empty($formConfig['privacy_note']) && !isset(array_column($formConfig['fields'], 'name')['privacy_accept'])): ?>
                            <div class="text-sm text-gray-600 mb-6 p-4 bg-gray-50 rounded-lg">
                                <i class="fa fa-shield-alt text-gray-400 mr-2"></i>
                                <?php echo htmlspecialchars($formConfig['privacy_note']); ?>
                                <?php if (!empty($formConfig['privacy_link'])): ?>
                                    <a href="<?php echo htmlspecialchars($formConfig['privacy_link']); ?>" class="text-blue-600 hover:underline" target="_blank">
                                        <?php echo htmlspecialchars($formConfig['texts']['view_details']); ?>
                                    </a>
                                <?php endif; ?>
                            </div>
                        <?php endif; ?>
                        
                        <div class="pt-4">
                            <button 
                                type="submit" 
                                class="w-full bg-gradient-to-r from-blue-600 to-indigo-700 hover:from-blue-700 hover:to-indigo-800 text-white font-semibold py-4 px-6 rounded-lg transition-all duration-300 flex items-center justify-center shadow-lg hover:shadow-xl transform hover:-translate-y-0.5"
                                id="submitButton"
                            >
                                <span id="submitText"><?php echo htmlspecialchars($formConfig['submit_text']); ?></span>
                                <i class="fa fa-paper-plane ml-2"></i>
                                <div id="loadingIndicator" class="ml-2 hidden">
                                    <i class="fa fa-spinner fa-spin"></i>
                                </div>
                            </button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>

<!-- 表单验证和提交脚本 -->
<script>
document.addEventListener('DOMContentLoaded', function() {
    // 从配置获取所有文本信息，消除硬编码
    const formConfig = {
        formId: 'feedbackForm',
        successMessage: <?php echo json_encode($formConfig['success_message'] ?? ''); ?>,
        errorMessage: <?php echo json_encode($formConfig['error_message'] ?? ''); ?>,
        networkErrorMessage: <?php echo json_encode($formConfig['network_error_message'] ?? '网络连接错误，请检查网络后重试'); ?>,
        submitText: <?php echo json_encode($formConfig['submit_text'] ?? ''); ?>,
        submitLoadingText: <?php echo json_encode($formConfig['submit_loading_text'] ?? ''); ?>,
        texts: <?php echo json_encode($texts); ?>
    };

    const form = document.getElementById(formConfig.formId);
    const submitButton = document.getElementById('submitButton');
    const submitText = document.getElementById('submitText');
    const loadingIndicator = document.getElementById('loadingIndicator');
    const successMessage = document.getElementById('form-success');
    const errorMessage = document.getElementById('form-error');
    const errorMessageText = document.getElementById('form-error-text');
    
    // 重置表单状态
    function resetFormState() {
        // 隐藏所有消息
        successMessage.classList.add('hidden');
        errorMessage.classList.add('hidden');
        
        // 重置所有字段错误状态
        document.querySelectorAll('.form-group').forEach(group => {
            const input = group.querySelector('input, textarea, select');
            const errorEl = group.querySelector('.error-message');
            
            if (input) input.classList.remove('border-red-500');
            if (errorEl) errorEl.classList.add('hidden');
        });
    }
    
    // 显示字段错误
    function showFieldError(field, message) {
        const formGroup = field.closest('.form-group');
        const errorEl = formGroup.querySelector('.error-message');
        
        field.classList.add('border-red-500');
        
        if (errorEl) {
            errorEl.textContent = message;
            errorEl.classList.remove('hidden');
        }
    }
    
    // 清除字段错误
    function clearFieldError(field) {
        const formGroup = field.closest('.form-group');
        const errorEl = formGroup.querySelector('.error-message');
        
        field.classList.remove('border-red-500');
        
        if (errorEl) {
            errorEl.textContent = '';
            errorEl.classList.add('hidden');
        }
    }
    
    // 验证单个字段
    function validateField(field) {
        const validation = field.dataset.validation ? JSON.parse(field.dataset.validation) : {};
        const value = field.type === 'checkbox' ? field.checked : field.value.trim();
        let isValid = true;
        let errorMessage = validation.error_message || formConfig.texts.default_field_error;
        
        // 必填验证
        if (field.required && !value) {
            isValid = false;
            errorMessage = formConfig.texts.required_field_error;
        }
        // 最小长度验证
        else if (validation.min_length && value.length < validation.min_length) {
            isValid = false;
        }
        // 最大长度验证
        else if (validation.max_length && value.length > validation.max_length) {
            isValid = false;
            errorMessage = formConfig.texts.max_length_error.replace('{max}', validation.max_length);
        }
        // 正则表达式验证
        else if (validation.pattern && value && !new RegExp(validation.pattern).test(value)) {
            isValid = false;
        }
        // 文件大小验证
        else if (field.type === 'file' && field.files.length > 0) {
            if (validation.max_size && field.files[0].size > validation.max_size) {
                isValid = false;
                const maxSizeMB = (validation.max_size / 1024 / 1024).toFixed(1);
                errorMessage = validation.error_message || formConfig.texts.file_size_error.replace('{max_size}', maxSizeMB);
            }
        }
        
        if (isValid) {
            clearFieldError(field);
        } else {
            showFieldError(field, errorMessage);
        }
        
        return isValid;
    }
    
    // 验证整个表单
    function validateForm() {
        let isFormValid = true;
        const fields = form.querySelectorAll('input, textarea, select');
        
        fields.forEach(field => {
            if (!validateField(field)) {
                isFormValid = false;
            }
        });
        
        return isFormValid;
    }
    
    // 字段实时验证
    form.querySelectorAll('input, textarea, select').forEach(field => {
        // 输入和失焦事件时验证
        field.addEventListener('input', () => validateField(field));
        field.addEventListener('blur', () => validateField(field));
        
        // 复选框和文件选择变化时验证
        if (field.type === 'checkbox' || field.type === 'file') {
            field.addEventListener('change', () => validateField(field));
        }
    });
    
    // 表单提交处理
    form.addEventListener('submit', async function(e) {
        e.preventDefault();
        resetFormState();
        
        // 客户端验证
        if (!validateForm()) {
            // 滚动到第一个错误字段
            const firstErrorField = document.querySelector('.border-red-500');
            if (firstErrorField) {
                firstErrorField.scrollIntoView({ behavior: 'smooth', block: 'center' });
                firstErrorField.focus();
            }
            return;
        }
        
        // 显示加载状态
        submitButton.disabled = true;
        submitText.textContent = formConfig.submitLoadingText;
        loadingIndicator.classList.remove('hidden');
        
        try {
            // 构建表单数据
            const formData = new FormData(form);
            
            // 发送表单数据到服务器
            const response = await fetch(form.action, {
                method: form.method,
                body: formData,
                headers: {
                    'Accept': 'application/json'
                }
            });
            
            const result = await response.json();
            
            if (response.ok && result.success) {
                // 提交成功
                successMessage.classList.remove('hidden');
                successMessage.querySelector('span').textContent = formConfig.successMessage;
                form.reset();
            } else {
                // 提交失败
                errorMessage.classList.remove('hidden');
                errorMessageText.textContent = result.message || formConfig.errorMessage;
                
                // 显示服务器返回的字段错误
                if (result.errors) {
                    Object.keys(result.errors).forEach(fieldName => {
                        const field = form.querySelector(`[name="${fieldName}"]`);
                        if (field) {
                            showFieldError(field, result.errors[fieldName]);
                        }
                    });
                }
            }
        } catch (error) {
            // 网络错误
            errorMessage.classList.remove('hidden');
            errorMessageText.textContent = formConfig.networkErrorMessage;
            console.error('表单提交错误:', error);
        } finally {
            // 恢复按钮状态
            submitButton.disabled = false;
            submitText.textContent = formConfig.submitText;
            loadingIndicator.classList.add('hidden');
        }
    });
});
</script>
